//index.js
const shikuang= require('../../config').shikuang;
const getCurrentPagesApi = require('../../utils/common').getCurrentPagesApi;
//获取应用实例
const app = getApp()

Page({
  data: {
    content:'',
    showModal:false,
    session:false,
    navs:[{img: "../../images/p1_3.png",name: "市场d况"},
          {img: "../../images/p1_4.png",name: "海关数据"},
          {img: "../../images/p1_5.png",name: "订购数据"},
          {img: "../../images/p1_6.png",name: "定制数据"},
          {img: "../../images/p1_7.png",name: "新闻资讯"},
          {img: "../../images/p1_8.png",name: "木材交易"},
          {img: "../../images/p1_9.png",name: "English"},
          {img: "../../images/p2_1.png",name: "Русский"}]

  },
  preventTouchMove: function () {
      // this.hideModal();
    },
  //事件处理函数
  bindViewTap: function() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  onShareAppMessage: function (res) {
    if (res.from === 'menu') {
      return {
        title: '国数源',
        path: getCurrentPagesApi()
      }
    }
    
  },
  showDialogBtn: function() {
      this.setData({
        showModal: true
      })
//       wx.showModal({
//   title: '提示',
//   content: `<button>微信登录<button>`,
//   success: function(res) {
//     if (res.confirm) {
//       console.log('用户点击确定')
//     } else if (res.cancel) {
//       console.log('用户点击取消')
//     }
//   }
// })
    },
    /**
     * 弹出框蒙层截断touchmove事件
     */
    
    /**
     * 隐藏模态对话框
     */
    hideModal: function () {
      this.setData({
        showModal: false
      });
    },
    /**
     * 对话框取消按钮点击事件
     */
    onCancel: function () {
      this.hideModal();
    },
    /**
     * 对话框确认按钮点击事件
     */
    onConfirm: function () {
      this.hideModal();
    },
    //  onShow:function(e){
    //    this.onLoad();
    // },
  onLoad: function () {
    // console.log(app.globalData.userInfo.avatarUrl);
    var that = this
    wx.getSetting({
      success: res => {
        if (res.authSetting['scope.userInfo']) {
          wx.checkSession({
            success: function(){
              // console.log(app.globalData.userInfo.avatarUrl);
              console.log('app.globalData.userInfo.avatarUrl');
              that.setData({
                session:true,
                content:app.globalData.userInfo.avatarUrl
              });
            },
            fail: function(){
              wx.login({
                success: function(){
                  wx.navigateTo({
                    url: "./user"
                  })
                }
              })
            }
          });
        }
      }
    })
    
  },
  weixin_login: function(){
    this.setData({
      showModal: false
    });
    wx.navigateTo({
      url: "../user/weixin_login"
    })
  },
  gsy_login: function(){
    this.setData({
      showModal: false
    });
    wx.navigateTo({
      url: "../user/gsy_login"
    })
  },
  ready: function() {
    var that = this
    wx.request({
      url: shikuang,
      success: function(res){
        console.log(res.data)
        that.setData({
          content: res.data
        })
      },
      fail: function(data){
        console.log(data)
      }
    })
  },
  getUserInfo: function(e) {
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  }
})
